/*
 * Vec2.h
 *
 *  Created on: 19.09.2009
 *      Author: christoph
 */

#ifndef VEC2_H_
#define VEC2_H_

#include "System.h"
#include "math/Math.h"

namespace mehari {
namespace common {

template < typename Real >
class Vec2 {
public:
	static void test() {
		Math<Real>::Sqrt( 3 );
	}
	// constructors

	Vec2();
	Vec2( const Real x, const Real y );
	Vec2( const Vec2<Real>& v );
	~Vec2();

	// access
	Real x() const;
	Real& x();
	Real y() const;
	Real& y();
	const Real operator [] ( int iIndex ) const;
	Real operator [] ( int iIndex );

	// arithmetic operations
	Vec2<Real> operator + ( const Vec2<Real>& vRhs ) const;
	Vec2<Real> operator - ( const Vec2<Real>& vRhs ) const;
	Vec2<Real> operator * ( const Real rRhs ) const;
	Vec2<Real> operator / ( const Real rRhs ) const;
	Vec2<Real> operator - () const;

	Vec2<Real> operator += ( const Vec2<Real>& vRhs );
	Vec2<Real> operator -= ( const Vec2<Real>& vRhs );
	Vec2<Real> operator *= ( const Real rRhs );
	Vec2<Real> operator /= ( const Real rRhs );

	// comparison operations
	bool operator == ( const Vec2<Real>& vRhs) const;
	bool operator != ( const Vec2<Real>& vRhs) const;
	bool operator <  ( const Vec2<Real>& vRhs) const;
	bool operator <= ( const Vec2<Real>& vRhs) const;
	bool operator >  ( const Vec2<Real>& vRhs) const;
	bool operator >= ( const Vec2<Real>& vRhs) const;

	// geometric operatons
	Real length() const;
	Real squaredLength() const;
	Real normalize();
	Real dot( const Vec2<Real>& vRhs ) const;

	// vec2 specific
	Vec2<Real> perp() const;
	Vec2<Real> unitPerp() const;
	Real dotPerp( const Vec2<Real>& v2Val ) const;

	static void orthonormalize( Vec2<Real>& v2U, Vec2<Real>& v2V );
	static void generateOrthonormalBasis( Vec2<Real>& v2U, Vec2<Real>& v2V, bool bUnitLengthV );


private:
	/**
	 * holds the data
	 * 0
	 * 1
	 */
	Real data[2];
};

template < typename Real >
Vec2<Real> operator * ( const Real rLhs, const Vec2<Real> vRhs ) {
	return Vec2<Real>( rLhs * vRhs.x(), rLhs * vRhs.y() );
}


} // namespace common
} // namespace mehari

#include "../src/types/Vec2.cpp.inl"

#endif /* VEC2_H_ */
